package com.tt.vtg.authn.otp.totp;

import org.springframework.stereotype.Component;

import com.tt.vtg.authn.otp.OTPHandler;
import com.tt.vtg.authn.otp.common.OTP;

@Component("totpHandler")
public class TOTPHandlerImpl implements OTPHandler {

	private static final String SECRECT_KEY = "JBSWY3DPEHPK3PXP";

	private static final int CODE_DIGITS = 6;

	private static final int PERIOD = 30;

	public boolean validateOTP(String otp) {
		if (otp == null || "".equals(otp)) {
			return false;
		}
		
		Long code = Long.parseLong(otp);
		return OTP.checkCode(SECRECT_KEY, code, System.currentTimeMillis());
	}

}
